package ch05_类与对象;

public class ConstructorDemo {
	boolean isFirstPrint = true;

	public static void main(String[] args) {
		Person p1 = new Person("Tom");
		Person p2 = new Person("Mary", 18, "30040019990401000x");
		ConstructorDemo demo = new ConstructorDemo();
		demo.print("P1", p1);
		p1.setAge(30);
		demo.print("p1", p1);
		p2.name = "Jack";
		p2.id = "200200198011084321";
		p2.setAge(25);
		demo.print("P2", p2);
		demo.print("Anonymous", new Person("joe"));
		System.out.println();
		p1.sleep(15);
		p1.sleep(30);

	}

	void print(String tag, Person p) {
		if (isFirstPrint) {
			System.out.printf("%-10s %-10s %-5s %s\n", "tag", "name", "age", "id");
			System.out.print("------------------------------------------\n");
			isFirstPrint = false;

		}
		System.out.printf("%-10s %-10s %-5d %s\n", tag, p.name, p.age, p.id);
	}
}
